import cv2
import os
# import pytesseract


# 读取图片
image_path = "C:\\Users\\zzg\\Desktop\\test2.png"
# 检查文件是否存在
if not os.path.isfile(image_path):
    print("错误：图像文件未找到！")
    exit()

image = cv2.imread(image_path)

# 灰度化图片
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 对图片进行缩放
image_big = cv2.resize(gray_image, dsize=(None, None), fx=3, fy=3, interpolation=cv2.INTER_CUBIC)

# 降噪图片
denoised_image = cv2.GaussianBlur(image_big, (5, 5), 0)

# 使用 OCR 识别文字
text = pytesseract.image_to_string( denoised_image,lang='chi_sim')

# 打印文字
print("识别出文字内容:"+text)

